﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.IO;
using System.Windows;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace SilverlightFTP
{
    public partial class MainPage : UserControl
    {
        FTPmanager m = new FTPmanager();
        ToolTip t = new ToolTip();
        DispatcherTimer timer = new DispatcherTimer();
        SortingType Sorting = SortingType.AZ;

        List<FileItem> buffer = new List<FileItem>();
        private delegate void ExistsDelegateOk();
        private delegate void ExistsDelegateCancel();
        private delegate void NewNameDelegateOk();
        private delegate void NewNameDelegateCancel();
        ExistsDelegateOk ExistsOkHandler;
        ExistsDelegateCancel ExistsCancelHandler;
        NewNameDelegateOk  NewNameOkHandler;
        NewNameDelegateCancel NewNameCancelHandler;
        AllowRename allowedrename = AllowRename.NotAllowed;
        int currentrenameposition = 0;
        bool ischeckedall = false;
        List<string> selectedpaths = new List<string>();

        public MainPage()
        {

            InitializeComponent();
            
            m.DeleteDirectoryCompleted += new FTPmanager.DeleteDirectoryCompletedEventHandler(m_DeleteDirectoryCompleted);
            m.BytesSentCompleted += new FTPmanager.BytesSentCompletedEventHandler(m_BytesSentCompleted);
            m.ListDirectoryCompleted += new FTPmanager.ListDirectoryCompletedEventHandler(m_ListDirectoryCompleted);
            m.BytesSentCompleted += new FTPmanager.BytesSentCompletedEventHandler(m_BytesSentCompleted);
            m.FileOperationFinished += new FTPmanager.FileOperationFinishedEventHandler(m_FileOperationFinished);
            m.FileOperationEnqued += new FTPmanager.FileOperationEnquedEventHandler(m_FileOperationEnqued);
            m.DownloadFileOperationEnqued += new FTPmanager.DownloadFileOperationEnquedEventHandler(m_DownloadFileOperationEnqued);
            m.DownloadFileOperationFinished += new FTPmanager.DownloadFileOperationFinishedEventHandler(m_DownloadFileOperationFinished);
            m.AlreadyExists += new FTPmanager.AlreadyExistsEventHandler(m_AlreadyExists);
            m.DeleteFileOperationFinished += new FTPmanager.DeleteFileOperationFinishedEventHandler(m_DeleteFileOperationFinished);
            t.Content = "In use";
            m.ban = new FTPmanager.BanItemDelegate(ban_item);
            m.unban = new FTPmanager.UnbanItemDelegate(unban_item);
            m.ProgramMessage += new FTPmanager.ProgramMessageHandler(m_ProgramMessage);
            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Tick += new EventHandler(timer_Tick);
            FileBox.AllowDrop = true;
            FileBox.Drop += new DragEventHandler(FileBox_Drop);
            //ProgressBox.ItemsSource = m.FileOperations;
            //DownProgressBox.ItemsSource = m.DownloadFileOperations;
        }

        void FileBox_Drop(object sender, DragEventArgs e)
        {
            object[] files = e.Data.GetData(DataFormats.FileDrop) as object[];
            foreach (FileInfo f in files)
            {
                if (f.Exists)
                {
                    m.UploadFile(f, m.CurrentPath + f.Name);
                }
            }
        }

        void m_ProgramMessage(object sender, ProgramEventArgs e)
        {
            ExistsOkHandler = new ExistsDelegateOk(HidePopup);
            ExistsCancelHandler = new ExistsDelegateCancel(HidePopup);
            ExistsText.Text = e.Message;
            ExistsPopUp.IsOpen = true;

        }

       
        private void ban_item(string f)
        {
            FileBox.UpdateLayout();
            foreach (FileItem fi in FileBox.Items)
            {
                if (fi.path == f)
                {
                    ((ListBoxItem)FileBox.ItemContainerGenerator.ContainerFromItem(fi)).IsEnabled = false;
                }
            }

        }
        private void unban_item(string f)
        {

            foreach (FileItem fi in FileBox.Items)
            {
                if (fi.path == f)
                {
                    ((ListBoxItem)FileBox.ItemContainerGenerator.ContainerFromItem(fi)).IsEnabled = true;
                }
            }
        }

        void m_DeleteFileOperationFinished(object sender, DeleteFileOperationFinishedEventArgs e)
        {
            FileItem delete = new FileItem();
            foreach (FileItem i in FileBox.Items)
            {
                if (i.path == e.Operation.path)
                {
                    delete = i;
                }
            }
            FileBox.Items.Remove(delete);
        }

        void NewNameRenameOk()
        {
            bool contains = false;
            foreach (FileItem i in FileBox.Items)
            {
                if (i.Name == EditTextBox.Text)
                {
                    contains = true;
                }
            }
            if (!contains)
            {
                m.RenameItem(CurrentNameTextBlock.Text, EditTextBox.Text, CurrentNameIsFolder.Text == "true");
                popUp.IsOpen = false;
            }
        }
        void HidePopup()
        {
            ExistsPopUp.IsOpen = false;
        }
        void NewNameRenameCancel()
        {
            popUp.IsOpen = false;
        }
        void NewNameCreateFolderOk()
        {
            bool contains = false;
            foreach (FileItem i in FileBox.Items)
            {
                if (i.Name == EditTextBox.Text)
                {
                    contains = true;
                }
            }
            if (!contains)
            {
                m.CreateDirectory(EditTextBox.Text);
                popUp.IsOpen = false;
            }
        }
        void NewNameCreateFolderCancel()
        {
            popUp.IsOpen = false;
        }
        void AlreadyExistsUpload()
        {
            ExistsOkHandler = new ExistsDelegateOk(AlreadyExistsUploadkOk);
            ExistsCancelHandler = new ExistsDelegateCancel(AlreadyExistsUploadkCancel);
        }
        void AlreadyExistsRename()
        {
            ExistsOkHandler = new ExistsDelegateOk(AlreadyExistsRenamekOk);
            ExistsCancelHandler = new ExistsDelegateCancel(AlreadyExistsRenameCancel);
        }
        void AlreadyExistsUploadkOk()
        {
            m.UploadFileOperations[0].allowed = true;
            m.FileOperationInitiator();
            ExistsPopUp.IsOpen = false;
        }
        void AlreadyExistsUploadkCancel()
        {
            ProgressBox.Items.Remove(m.UploadFileOperations[0]);
            m.CancelFileOperationNoDelete(m.UploadFileOperations[0]);
            ExistsPopUp.IsOpen = false;
        }
        void AlreadyExistsRenamekOk()
        {
            allowedrename = AllowRename.Allowed;
            ExistsPopUp.IsOpen = false;
            RenameCicle(currentrenameposition);
        }
        void AlreadyExistsRenameCancel()
        {
            allowedrename = AllowRename.Canceled;
            ExistsPopUp.IsOpen = false;
            RenameCicle(currentrenameposition);
        }
        void m_AlreadyExists(object sender, AlreadyExistsEventArgs e)
        {
            ExistsText.Text = e.Message + " already exists. Rewrite?";
            AlreadyExistsUpload();
            popUp.IsOpen = false;
            ExistsPopUp.IsOpen = true;
        }

        void m_DownloadFileOperationFinished(object sender, DownloadFileOperationFinishedEventArgs e)
        {
            DownProgressBox.Items.RemoveAt(0);
        }

        void m_DownloadFileOperationEnqued(object sender, DownloadFileOperationFinishedEventArgs e)
        {
            DownProgressBox.Items.Add(e.Operation);
        }

        void m_FileOperationEnqued(object sender, FileOperationFinishedEventArgs e)
        {
            ProgressBox.Items.Add(e.Operation);
        }

        void m_FileOperationFinished(object sender, FileOperationFinishedEventArgs e)
        {
            ProgressBox.Items.RemoveAt(0);
        }
        /// <summary>
        /// Здесь парсим ответ listftp и создаём item'ы
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void m_ListDirectoryCompleted(object sender, ListDirectoryCompletedEventArgs e)
        {
            FileBox.Items.Clear();
            FileBox.IsEnabled = true;
            FileItem back = new FileItem();
            back.Name = "..";
            back.isFolder = true;
            back.path = e.Message[1].Path;
            FileBox.Items.Add(back);


            FTPConnectorRef.FsItem[] ma = e.Message.Skip(2).ToArray();
            for (int j = 0; j < ma.Length; j++)
            {
                FileItem f = new FileItem();
                f.Name = ma[j].Name;
                f.IsFolder = ma[j].IsFolder;
                f.Filesize = ma[j].Size;
                f.Path = ma[j].Path;
                FileBox.Items.Add(f);

            }
            FileBox.UpdateLayout();


            
        }

        private void GetChildren(UIElement parent, Type targetType, ref List<UIElement> children)
        {
            int count = VisualTreeHelper.GetChildrenCount(parent);
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i);
                    if (child.GetType() == targetType)
                    {
                        children.Add(child);
                    }
                    GetChildren(child, targetType, ref children);
                }
            }
        }
        void m_BytesSentCompleted(object sender, BytesSentCompletedEventArgs e)
        {

        }

        void m_DeleteDirectoryCompleted(object sender, DeleteDirectoryCompletedEventArgs e)
        {


        }
        private void ListBox1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void ConnectButton_Click(object sender, RoutedEventArgs e)
        {
            if (TbHost.Text != "" && TbUser.Text != "" && TbPass.Password != "")
            {
                m.FtpHost = TbHost.Text;
                m.User = TbUser.Text;
                m.Password = TbPass.Password;
                FileBox.Items.Clear();
                m.ListDirectory(m.FtpHost);
            }
        }
        /// <summary>
        /// Добавляем дабл клик к ListItem'ам
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        
        public void ListItem_DoubleClick(object sender, RoutedEventArgs e)
        {

            FileItem item = (FileItem)FileBox.SelectedItem;
            if (item.isFolder == true)
            {
                m.ListDirectory(item.path + "/");
                FileBox.IsEnabled = false;
            }
        }
        /// <summary>
        /// Вспомогательный класс 
        /// </summary>
        public class FileItem : INotifyPropertyChanged
        {
            public event PropertyChangedEventHandler PropertyChanged;
            private bool isSelected = false;
            private bool asd;
            public bool IsSelected
            {
                get { return isSelected; }
                set { 
                    if (Name!="..")
                    {
                    isSelected = value;
                    }
                    else isSelected = false;

                if (PropertyChanged != null)
                {

                    PropertyChanged(this, new PropertyChangedEventArgs("IsSelected"));
                }
                }
            }
            private String name;
            public String Name
            {
                get { return name; }
                set { name = value; }
            }
            public String path;
            public String Path
            {
                get { return path; }
                set { path = value; }
            }
            public long filesize;
            public long Filesize
            {
                get { return filesize; }
                set { filesize = value; }
            }
            public String StrFilesize
            {
                get
                {
                    if (filesize != 0) return filesize.ToString();
                    else return "";
                }
            }
            public bool isFolder;
            public bool IsFolder
            {
                get { return isFolder; }
                set { isFolder = value; }
            }
            
            public bool IsFile
            {
                get { return !isFolder; }
            }
            public bool DisabledForFolders
            {
                get { 
                    if (Name == "..")return false; 
                    if (IsFolder)return false; else return true; }
            }
            public double OpacityForFolders
            {
                get
                {
                    if (Name == "..") return 0;
                    if (IsFolder)return 0; 
                else return 1; }
            }
            public bool EnabledForFolders
            {
                get
                {
                    if (Name == "..") return false;
                    else return true;
                }
            }
            public double NoOpacityForFolders
            {
                get { if (Name == "..") return 0;else return 1; }
            }
            public Visibility FileIcon
            {
                get
                {
                    if (!isFolder) return Visibility.Visible;
                    else return Visibility.Collapsed;
                }
            }
            public Visibility FolderIcon
            {
                get
                {
                    if (isFolder) return Visibility.Visible;
                    else return Visibility.Collapsed;
                }
            }
        }


        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            FTPFileOperation f = (FTPFileOperation)((Button)sender).DataContext;
            if (ProgressBox.Items.IndexOf(f) != 0 || m.Pause)
            {
                ProgressBox.Items.Remove(f);
            }
            m.CancelFileOperation(f);
        }
        private void CancelDownButton_Click(object sender, RoutedEventArgs e)
        {
            FTPDownloadFileOperation f = (FTPDownloadFileOperation)((Button)sender).DataContext;
            if (DownProgressBox.Items.IndexOf(f) != 0 || m.Pause)
            {
                DownProgressBox.Items.Remove(f);
            }
            m.CancelDownFileOperation(f);
        }
        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            selectedpaths.Add(((FileItem)((CheckBox)sender).DataContext).path);
            ((FileItem)((CheckBox)sender).DataContext).IsSelected = true;
        }

        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            selectedpaths.Remove(((FileItem)((CheckBox)sender).DataContext).path);
            ((FileItem)((CheckBox)sender).DataContext).IsSelected = false;
        }

        private void DeleteCheckedButton_Click(object sender, RoutedEventArgs e)
        {
            FileBox.IsEnabled = false;
            foreach (FileItem i in FileBox.Items)
            {
                if (selectedpaths.Contains(i.path))
                {
                    if (i.isFolder)
                    {
                        m.DeleteDirectory(i.path);
                    }
                    else m.DeleteFile(i.path);
                }
            }
            m.ListDirectory(m.CurrentPath);
        }

        private void UploadButton_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog(); // Диалоговое окно выбора файлов
            dlg.Multiselect = true;      // Запрещаем множественный выбор файлов

            dlg.Filter = "All Files|*.*";   // Устанавливаем фильтр на файлы
            if ((Boolean)dlg.ShowDialog())   // показываем диалог выбора файлов
            {
                foreach (FileInfo f in dlg.Files)
                {
                    m.UploadFile(f, m.CurrentPath + f.Name);
                }
            }
        }

        private void DeleteItemButton_Click(object sender, RoutedEventArgs e)
        {
            FileItem item = (FileItem)((Button)sender).DataContext;
            ((ListBoxItem)FileBox.ItemContainerGenerator.ContainerFromItem(item)).IsEnabled = false;
            if (!InUse(item.Path))
            {
                if (item.isFolder)
                {
                    m.DeleteDirectory(item.path);
                }
                else m.DeleteFile(item.path);
            }
        }

        private void CancelAllButton_Click(object sender, RoutedEventArgs e)
        {
            if (m.Pause)
            {
                for (int i = 0; i < m.UploadFileOperations.Count; i++)
                {
                    ProgressBox.Items.Remove(m.UploadFileOperations[i]);
                    m.CancelFileOperation(m.UploadFileOperations[i]);
                }
                for (int i = 0; i < m.DownloadFileOperations.Count; i++)
                {
                    DownProgressBox.Items.Remove(m.DownloadFileOperations[i]);
                    m.CancelDownFileOperation(m.DownloadFileOperations[i]);
                }
            }
            else
            {
                if (m.UploadFileOperations.Count > 0)
                {
                    for (int i = m.UploadFileOperations.Count - 1; i > 0; i--)
                    {
                        ProgressBox.Items.Remove(m.UploadFileOperations[i]);
                        m.CancelFileOperation(m.UploadFileOperations[i]);
                    }
                    m.CancelFileOperation(m.UploadFileOperations[0]);
                }
                if (m.DownloadFileOperations.Count > 0)
                {
                    for (int i = m.DownloadFileOperations.Count - 1; i > 0; i--)
                    {
                        DownProgressBox.Items.Remove(m.DownloadFileOperations[i]);
                        m.CancelDownFileOperation(m.DownloadFileOperations[i]);
                    }
                    m.CancelDownFileOperation(m.DownloadFileOperations[0]);
                }
            }
        }

        private void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            FileItem item = (FileItem)((Button)sender).DataContext;
            if (!InUse(item.Path))
            {
                var dlg = new SaveFileDialog(); // Диалоговое окно выбора файлов    
                if ((Boolean)dlg.ShowDialog())   // показываем диалог выбора файлов
                {
                    m.DownloadFile(dlg.OpenFile(), item.Path
                        , item.Name, item.Filesize);
                }
            }
        }

        private void RenameButton_Click(object sender, RoutedEventArgs e)
        {
            if (!InUse(((FileItem)((Button)sender).DataContext).Path))
            {
                NewNameTextBlock.Text = "Type new name";
                popUp.IsOpen = true;
                EditTextBox.Text = ((FileItem)((Button)sender).DataContext).Name;
                NewNameCancelHandler = new NewNameDelegateCancel(NewNameRenameCancel);
                NewNameOkHandler = new NewNameDelegateOk(NewNameRenameOk);
                if (((FileItem)((Button)sender).DataContext).isFolder)
                {
                    CurrentNameIsFolder.Text = "true";
                }
                else CurrentNameIsFolder.Text = "false";
                CurrentNameTextBlock.Text = ((FileItem)((Button)sender).DataContext).Path;
            }
        }

        void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
            t.IsOpen = false;
        }

        private void CancelRenButton_Click(object sender, RoutedEventArgs e)
        {
            NewNameCancelHandler();
        }

        private void OkRenButton_Click(object sender, RoutedEventArgs e)
        {
            NewNameOkHandler();
        }

        private bool InUse(string path)
        {
            foreach (FTPBasicOperation fop in m.Operations)
            {
                if (fop.path == path)
                {
                    t.IsOpen = false;
                    timer.Stop();
                    t.IsOpen = true;
                    timer.Start();
                    return true;
                }
            }
            foreach (FTPFileOperation fop in m.UploadFileOperations)
            {
                if (fop.hostdestination == path)
                {
                    t.IsOpen = false;
                    timer.Stop();
                    t.IsOpen = true;
                    timer.Start();
                    return true;
                }
            }
            foreach (FTPDownloadFileOperation fop in m.DownloadFileOperations)
            {
                if (fop.hostdestination == path)
                {
                    t.IsOpen = false;
                    timer.Stop();
                    t.IsOpen = true;
                    timer.Start();
                    return true;
                }
            }
            return false;

        }

        private void CancelExistsButton_Click(object sender, RoutedEventArgs e)
        {
            ExistsCancelHandler();
        }

        private void OkExistsButton_Click(object sender, RoutedEventArgs e)
        {

            ExistsOkHandler();
        }

        private void ASortingButton_Click(object sender, RoutedEventArgs e)
        {
            if (Sorting == SortingType.AZ)
            {
                Sorting = SortingType.ZA;
            }
            else
            {
                Sorting = SortingType.AZ;
            }
            Sort();
        }

        private void SSortingButton_Click(object sender, RoutedEventArgs e)
        {
            if (Sorting == SortingType.UP)
            {
                Sorting = SortingType.DOWN;
            }
            else
            {
                Sorting = SortingType.UP;
            }
            Sort();
        }
        public void Sort()
        {



            //foreach (FileItem f in FileBox.Items)
            //{
            //    ItemsToDeactivate.Clear();
            //    if (f.IsFolder)
            //    {
            //        GetChildren((ListBoxItem)FileBox.ItemContainerGenerator.ContainerFromItem(f), typeof(Button), ref ItemsToDeactivate);
            //        foreach (Control b in ItemsToDeactivate)
            //        {
            //            if (b.Name == "RenameItemButton" || b.Name == "DownloadItemButton")
            //            {
            //                b.IsEnabled = false;
            //                b.Opacity = 0;
            //            }
            //        }    
            //    }
            //    ItemsToDeactivate.Clear();
            //    foreach (string i in m.BannedItems)
            //    {
            //        if (i == f.path)
            //        {

            //            ((ListBoxItem)FileBox.ItemContainerGenerator.ContainerFromItem(f)).IsEnabled = false;
            //        }

            //    }
            //}
        }
        private void CopySelectedButton_Click(object sender, RoutedEventArgs e)
        {
            buffer.Clear();
            foreach (FileItem i in FileBox.Items)
            {
                if (i.IsSelected == true)
                {
                    buffer.Add(i);
                }
            }
        }
        private void SolveProblem(string name)
        {
            AlreadyExistsRename();
            ExistsText.Text = name + " already exists. Rewrite?";
            popUp.IsOpen = false;
            ExistsPopUp.IsOpen = true;
        }
        public void RenameCicle(int pos)
        {
            if (pos != -1)
            {
                for (int i = pos; i < buffer.Count; i++)
                {
                    if (buffer[i].isFolder && m.CurrentPath.Contains(buffer[i].path))
                    {

                    }
                    else
                    {
                        //buffer[i].path
                        FileItem match = new FileItem();
                        foreach (FileItem f in FileBox.Items)
                        {
                            if (buffer[i].Name == f.Name)
                            {
                                match = f;
                            }
                        }
                        if (match.path != null)
                        {
                            if (buffer[i].path != match.path && buffer[i].Name == match.Name)
                            {
                                if (allowedrename == AllowRename.NotAllowed)
                                {
                                    currentrenameposition = i;
                                    SolveProblem(match.Name);
                                    return;
                                }
                                else if (allowedrename == AllowRename.Canceled)
                                {
                                }
                                else if (allowedrename == AllowRename.Allowed)
                                {
                                    if (match.isFolder)
                                    {
                                        m.DeleteDirectory(match.path);
                                    }
                                    else m.DeleteFile(match.path);
                                    m.RenameItem(buffer[i].path, buffer[i].Name, buffer[i].IsFolder);
                                    allowedrename = AllowRename.NotAllowed;
                                }
                            }
                        }
                        else m.RenameItem(buffer[i].path, buffer[i].Name, buffer[i].IsFolder);
                    }

                }
            }
            m.ResumeFileOperations();
            currentrenameposition = -1;
            buffer.Clear();
        }
        private void PasteSelectedButton_Click(object sender, RoutedEventArgs e)
        {
            m.PauseFileOperations();
            RenameCicle(0);
        }

        private void PauseButton_Click(object sender, RoutedEventArgs e)
        {
            if (m.Pause)
            {
                ((Button)sender).Content = "Pause";
                m.ResumeFileOperations();
            }
            else
            {
                ((Button)sender).Content = "Continue";
                m.PauseFileOperations();
            }

        }

        private void CopyItemButton_Click(object sender, RoutedEventArgs e)
        {
            buffer.Clear();
            buffer.Add((FileItem)((Button)sender).DataContext);
        }


        private void CheckAllButton_Click(object sender, RoutedEventArgs e)
        {

            foreach (FileItem f in FileBox.Items)
            {
                f.IsSelected = ischeckedall;
            }
            ischeckedall = !ischeckedall;
        }

        private void FileBox_LayoutUpdated(object sender, EventArgs e)
        {
            List<UIElement> ItemsToDeactivate = new List<UIElement>();
            GetChildren((ListBoxItem)FileBox.ItemContainerGenerator.ContainerFromIndex(0), typeof(Button), ref ItemsToDeactivate);
            GetChildren((ListBoxItem)FileBox.ItemContainerGenerator.ContainerFromIndex(0), typeof(CheckBox), ref ItemsToDeactivate);
            foreach (Control b in ItemsToDeactivate)
            {
                b.IsEnabled = false;
                b.Opacity = 0;
            }
        }

        private void ItemContentPanel_Loaded(object sender, RoutedEventArgs e)
        {
            GraphicsUtils gu = new GraphicsUtils();
            gu.AttachDoubleClick(sender, ListItem_DoubleClick);
        }

        private void CreateNewFolderButton_Click(object sender, RoutedEventArgs e)
        {
            
                popUp.IsOpen = true;
                NewNameTextBlock.Text = "New directory name";
                EditTextBox.Text = "";
                NewNameOkHandler = new NewNameDelegateOk(NewNameCreateFolderOk);
                NewNameCancelHandler = new NewNameDelegateCancel(NewNameCreateFolderCancel);
            
        }

        private void RefreshButton_Click(object sender, RoutedEventArgs e)
        {
            m.ListDirectory(m.CurrentPath);
            FileBox.IsEnabled = false;
        }


    }
    enum SortingType { AZ, ZA, UP, DOWN };
    enum AllowRename { AlwaysAllowed, Allowed, Canceled, NotAllowed };

}
